<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
    String contextPath = request.getContextPath();
%>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="<%=contextPath%>/resources/easyUI/themes/gray/easyuia.css">
    <link rel="stylesheet" type="text/css" href="<%=contextPath%>/resources/easyUI/icon.css">
    <link rel="stylesheet" type="text/css" href="<%=contextPath%>/resources/query-form.css">
    <script type="text/javascript" src="<%=contextPath%>/resources/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="<%=contextPath%>/resources/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="<%=contextPath%>/resources/easyUI/easyui-lang-zh_CN.js"></script>
    <script type='text/javascript' src='<%=contextPath%>/resources/js/manager/user.js'></script>
</head>
<body>
<div id="content" style="height: 100%">
    <div class="time">
        <form action="<%=contextPath%>/manager/admin/userList.do" id="ff" method="post">
        <input type="hidden" name="limit" value="20">
        <input type="hidden" id="pageNum" name="pageNum" value="1">
            <ul>
                <li>
                    <label> 用户名：<input class="easyui-textbox" type="text" name="name" id="name" /></label>
                    <label> <a href="#" onclick="CRUD.queryList();" class="easyui-linkbutton" iconCls="icon-search">查询</a> </label>
                </li>
            </ul>
        </form>
    </div>

    <div id="tablepanel" class="easyui-panel" style="width:'100%';height:auto;padding:10px;padding-right: 25px;" title="用户列表">
	<table id="tt" style="width:auto;height:auto;" rownumbers="true" ></table>
	</div>
</div>

<div id="dialogAdd">
    <form id="fmAdd" name="formHead" style="text-align:right;padding-top: 10px;height: 95%;width: 100%" method="post" action="<%=contextPath%>/manager/admin/userAdd.do">
        <input type="hidden" name="id" id="id"/>
        <table style="text-align:left;padding-left: 80px;width: 95%" id="ruleTable">
            <tr>
                <td >用户名:</td>
                <td ><input class="easyui-textbox" style="width:200px;" type="text" name="userName" id="userName"/></td>
            </tr>
            <tr>
                <td >密码:</td>
                <td ><input class="easyui-textbox" style="width:200px;" type="password" name="password" id="password"/></td>
            </tr>
            <tr>
                <td >电话:</td>
                <td ><input class="easyui-textbox" style="width:200px;" type="text" name="tel" id="tel"/></td>
            </tr>
            <tr>
                <td >Email:</td>
                <td ><input class="easyui-textbox" style="width:200px;" type="text" name="email" id="email"/></td>
            </tr>
            <tr>
                <td style="text-align:right">状态:</td>
                <td >
                   <select style="width:200px;height:24px" id="status" name="status" class="easyui-combobox" >
                        <option value="1" selected="selected">正常</option>
                        <option value="2" >停止</option>
                    </select>
                </td>
            </tr>
        </table>
        </br>
        <div style = "margin-right:40%">
        <a class="easyui-linkbutton" id="a_AddOK" onclick="">确定</a>
        <a class="easyui-linkbutton" id="a_AddCancle">取消</a>
        </div>
    </form>
</div>

<div id="roles">
        <input type="hidden" name="id"/>
        <input type="hidden" id="aid"/>
        <table class="easyui-datagrid" style="text-align:left;padding-left: 100px;width: 100%;height: 490px;" id="ruleTable2" 
       		 data-options="fitColumns:true">
        	<thead>   
		        <tr>   
		            <th data-options="field:'code',width:360">角色名称</th>   
		            <th data-options="field:'name',align:'center',width:100">是否勾选</th>   
		        </tr>   
		    </thead>
            <c:forEach var="roleList" items="${roleList}">
                <tr>
                    <td>${roleList.name}:</td>
                    <td ><input style="width:100px;" type="checkbox" id= "roleId" name="roleId" value="${roleList.id}" onclick="selectRole(this)" /></td>
                </tr>
            </c:forEach>
        </table>
</div>

<div id="permissions">
    <input type="hidden" name="id"/>
    <input type="hidden" id="aid2"/>
    <table class="easyui-datagrid"  style="text-align:left;padding-left: 20px;width: 100%;height: 850px;" id="permissionTable2" data-options="fitColumns:true">
	    <thead>   
	        <tr>   
	            <th data-options="field:'code',width:360">权限名称</th>   
	            <th data-options="field:'name',align:'center',width:100">是否勾选</th>   
	        </tr>   
	    </thead>
        <c:forEach var="permissionList" items="${permissionList}">
            <tr>
                <td >${permissionList.name}:</td>
                <td ><input style="width:100px;" type="checkbox" id= "permissionId" name="permissionId" value="${permissionList.id}" onclick="selectPermission(this)" /></td>
            </tr>
        </c:forEach>
    </table>
</div>

</body>

<script type="text/javascript">
    function showHavaRoles(aid) {
        $("#aid").val(aid);
        $.ajax({
            url: "/manager/admin/roleAll.do?id=" + aid,
            type: "GET",
            contentType: "application/json",
            dataType:"json",
            success:function(DATA) {
                $("input[name='roleId']").each(function(){                    /*清空*/
                    var rid =  Number($(this).attr('value'));
                    $(this).attr("checked",false);
                });
                var objArr = DATA[0];
                var roleIdList = new Array();
                for(var i=0;i<objArr.length;i++) {           /*获得该用户所拥有角色的id*/
                    roleIdList[i] = objArr[i];
                }
                $("input[name='roleId']").each(function(){                    /*选中用户拥有的角色*/
                    var rid =  Number($(this).attr('value'));
                    if(roleIdList.indexOf(rid)>=0)
                    {$(this).attr("checked",true);}
                });
            },
             error:function(XMLHttpRequest, textStatus, errorThrown) {
                alert("请刷新重试");
             }
        })
    }

    function selectRole(obj) {
        if(obj.checked) {
            $.ajax({
                url: "/manager/admin/roleAdd.do?aid=" + $("#aid").val() + "&rid=" + obj.value,
                type: "GET",
                contentType: "application/json",
                dataType:"json",
                success:function(DATA) {
                	
                },
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("请刷新重试");
                }
            })
        } else {
            $.ajax({
                url: "/manager/admin/roleDelete.do?aid=" + $("#aid").val() + "&rid=" + obj.value,
                type: "GET",
                contentType: "application/json",
                dataType:"json",
                success:function(DATA) {
                	
                },
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("请刷新重试");
                }
            })
        }
    }

    function showHavaPermissions(rid) {
        $("#aid2").val(rid);
        $.ajax({
            url: "/manager/admin/permissionAll.do?id=" + rid,
            type: "GET",
            contentType: "application/json",
            dataType:"json",
            success:function(DATA) {
                $("input[name='permissionId']").each(function(){                    /*清空*/
                    var rid =  Number($(this).attr('value'));
                    $(this).attr("checked",false);
                });
                var objArr = DATA[0];
                var roleIdList = new Array();
                for(var i=0;i<objArr.length;i++) {           /*获得该用户所拥有权限的id*/
                    roleIdList[i] = objArr[i];
                }
                $("input[name='permissionId']").each(function(){                    /*选中用户拥有的权限*/
                    var rid =  Number($(this).attr('value'));
                    if(roleIdList.indexOf(rid)>=0)
                    {$(this).attr("checked",true);}
                });
            },
            error:function(XMLHttpRequest, textStatus, errorThrown) {
                alert("请刷新重试");
            }
        })
    }

    function selectPermission(obj) {
        if(obj.checked) {
            $.ajax({
                url: "/manager/admin/permissionAdd.do?aid=" + $("#aid2").val() + "&pid=" + obj.value,
                type: "GET",
                contentType: "application/json",
                dataType:"json",
                success:function(DATA) {
                	
                },
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("请刷新重试");
                }
            })
        } else {
            $.ajax({
                url: "/manager/admin/permissionDelete.do?aid=" + $("#aid2").val() + "&pid=" + obj.value,
                type: "GET",
                contentType: "application/json",
                dataType:"json",
                success:function(DATA) {
                	
                },
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("请刷新重试");
                }
            })
        }
    }
</script>
</html>